package cn.zkrt.iotms.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MybatisPlusConfig {

    @Value("${spring.datasource.driver-class-name}")
    private  String DB_TYPE = "com.mysql.cj.jdbc.Driver";

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // 通过配置文件区分数据库类型 DM还是 MYSQL
        // dm.jdbc.driver.DmDriver
        if (DB_TYPE.equalsIgnoreCase("dm")) {
            interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.DM));
            // 达梦数据库
         }else{
            interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        }



        return interceptor;
    }
}
